package com.bwie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.poi.StringUtils;
import com.bwie.pojo.TbBrand;
import com.bwie.pojo.TbProd;
import com.bwie.service.TbBrandService;
import com.bwie.mapper.TbBrandMapper;
import com.bwie.utils.R;
import com.bwie.vo.PageInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
* @author 叶雨洁
* @description 针对表【tb_brand(品牌表)】的数据库操作Service实现
* @createDate 2025-07-20 18:58:11
*/
@Service
public class TbBrandServiceImpl extends ServiceImpl<TbBrandMapper, TbBrand>
    implements TbBrandService{

    @Autowired
    TbBrandMapper brandMapper;
    @Override
    public R BradList(PageInfoVo pageInfoVo) {

        Page<TbBrand> tbBrandPage = new Page<>(pageInfoVo.getPageNum(), pageInfoVo.getPageSize());
        QueryWrapper<TbBrand> queryWrapper = new QueryWrapper<>();
        if(StringUtils.isNotEmpty(pageInfoVo.getKeyWord())){
            queryWrapper.lambda().like(TbBrand::getBrandName,pageInfoVo.getKeyWord());
        }
        queryWrapper.lambda().orderByDesc(TbBrand::getCreateTime);
        Page<TbBrand> tbBrandPage1 = brandMapper.selectPage(tbBrandPage, queryWrapper);
        return R.OK(tbBrandPage1);
    }

    @Override
    public R tbAdd(TbBrand tbBrand) {

        tbBrand.setCreateTime(new Date());
        tbBrand.setCreateBy("admin");
        brandMapper.insert(tbBrand);
        return R.OK();
    }

    @Override
    public R updateStatus(Integer brandId) {

        TbBrand tbBrand = brandMapper.selectById(brandId);
        if(tbBrand.getBrandStatus()==0){
            tbBrand.setBrandStatus(1);
        }else{
            tbBrand.setBrandStatus(0);
        }
        brandMapper.updateById(tbBrand);
        return R.OK();
    }

    @Override
    public R getBrandList() {

        List<TbBrand> tbBrands = brandMapper.selectList(null);


        return R.OK(tbBrands);
    }


}




